<?php
/**
 * Controller used for authenticated pages
 *
 * @author André Silva
 */
class ProtectedController extends PublicController {
	/**
	 * @var IUser
	 */
	public $loggedUser;
	/**
	 * Required permission to access the controller
	 * @var int
	 */
	private $permission = 0;

	function __construct() {
		parent::__construct();

		if (!Authentication::isLogged()) {
			Authentication::setRedirectPage(Cerberus::getControllerName());
			$this->redirect(Authentication::getLoginPage());
		}

		$this->loggedUser = Authentication::getUser();
		if (!$this->loggedUser->hasPermission($this->permission)) {
			$this->view = null;
			$this->loadTemplate(APPLICATION_TEMPLATE);
			$this->addError('You don\'t have permission to access this page', 'warning');
		}
	}
}
?>
